package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_7_28_Training {
    //统计按位或能得到最大值的子集数目
    public int countMaxOrSubsets(int[] nums) {
        int target = nums[0];
        for (int i = 1; i < nums.length; i++) {
            target |= nums[i];
        }
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            res += countMaxOrSubsets(nums, i, target, nums[i]);
        }
        return res;
    }

    public int countMaxOrSubsets(int[] nums, int start, int target, int cur) {
        int res = 0;
        if (target == cur) {
            res++;
        }
        for (int i = start + 1; i < nums.length; i++) {
            res += countMaxOrSubsets(nums, i, target, cur | nums[i]);
        }
        return res;
    }
}
